﻿<%@ Page Title="" Language="C#" MasterPageFile="~/Site.Master" AutoEventWireup="true" CodeBehind="Edit.aspx.cs" Inherits="MonkeyWarranty.Web.InstantTickets.Edit" %>
<%@ Import Namespace="Resources" %>
<asp:Content ID="Content1" ContentPlaceHolderID="HeadContent" runat="server">
    <title><%=GlobalStrings.InstantTickets %></title>
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server">
    <div class="row">
        <div class="col-lg-12">
            <h3><%=GlobalStrings.InstantTicketForm %> - <%=GlobalStrings.InstantTickets %></h3>
        </div>
    </div>
    <div class="row">
        <div class="col-lg-12">
            <div class="alert alert-danger" runat="server" id="errorMessage" visible="False">
                <label class="control-label">
                    <asp:Literal ID="lblErrorMessage" runat="server"></asp:Literal></label>
            </div>
        </div>
    </div>
    
    <!-- Customer -->
    <div class="row">
        <div class="col-lg-12">
            <div class="panel panel-default">
                <div class="panel-heading">
                    <%=GlobalStrings.Customers %>
                </div>
                <div class="panel-body">
                    <asp:HiddenField ID="hidCustomerId" runat="server" />
                    <div class="col-lg-6">
                        <div class="form-group">
                            <label><%=GlobalStrings.Name%></label>
                            <asp:TextBox ID="txtName" runat="server" CssClass="form-control"></asp:TextBox>
                        </div>
                        <div class="form-group">
                            <label><%=GlobalStrings.Address%></label>
                            <asp:TextBox ID="txtAddress" runat="server" CssClass="form-control"></asp:TextBox>
                        </div>
                    </div>
                    <div class="col-lg-6">
                        <div class="form-group">
                            <label><%=GlobalStrings.Phone%></label>
                            <asp:TextBox ID="txtPhone" runat="server" CssClass="form-control"></asp:TextBox>
                        </div>
                        <div class="form-group">
                            <label><%=GlobalStrings.Email%></label>
                            <asp:TextBox ID="txtEmail" runat="server" CssClass="form-control"></asp:TextBox>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
    
    <!-- End Customer -->
    
    <!-- Common information -->
    <div class="row">
        <div class="col-lg-12">
            <div class="panel panel-default">
                <div class="panel-heading">
                    <%=GlobalStrings.Information %>
                </div>
                <div class="panel-body">
                    <div class="col-lg-12">
                        <div class="form-group">
                            <label><%=GlobalStrings.TicketNumber %></label><br />
                            <asp:TextBox ID="txtCodePrefix" runat="server" Enabled="False" Text="TN" CssClass="codeprefix"></asp:TextBox>
                            - 
                            <asp:TextBox ID="txtCode" runat="server" Enabled="False" CssClass="codeprefix"></asp:TextBox>
                        </div>
                    </div>
                    <div class="col-lg-12">
                        <div class="form-group">
                            <label><%=GlobalStrings.InstantTicketContent %></label>
                            <asp:TextBox ID="txtContent" runat="server" CssClass="form-control"></asp:TextBox>
                        </div>
                    </div>
                    <div class="col-lg-4">
                        <div class="form-group">
                            <label><%=GlobalStrings.ReceivedDate %></label><br />
                            <asp:TextBox ID="txtReceivedDate" runat="server"></asp:TextBox>
                        </div>
                    </div>
                    <%--<div class="col-lg-4">
                        <div class="form-group">
                            <label><%=GlobalStrings.ReceivedEmployee %></label><br/>
                            <asp:DropDownList ID="ddlEmployees" runat="server"></asp:DropDownList>
                        </div>
                    </div>--%>
                    <div class="col-lg-4">
                        <div class="form-group">
                            <label><%=GlobalStrings.Distance %></label><br/>
                            <asp:TextBox ID="txtDistance" runat="server"></asp:TextBox> (km)
                        </div>
                    </div>
                    
                    <div class="col-lg-12">
                        <div class="form-group">
                            <label><%=GlobalStrings.Description %></label>
                            <asp:TextBox ID="txtDescription" runat="server" TextMode="MultiLine" CssClass="form-control"></asp:TextBox>
                        </div>
                    </div>
                    
                    <div class="col-lg-12">
                        <div class="form-group">
                            <label><%=GlobalStrings.Status %></label><br />
                            <asp:DropDownList ID="ddlTicketStatus" runat="server"></asp:DropDownList>
                        </div>
                    </div>

                    <div class="col-lg-12">
                        <asp:Button ID="btnSave" runat="server"
                            Text="<%$ Resources:GlobalStrings, Save %>" CssClass="btn btn-primary" Width="100px"
                            OnClick="btnSave_Click" />
                        <a class="btn btn-default" target="_blank" href="Print.aspx?id=<%=Request.Params["id"] %>"><i class="fa fa-print fa-fw"></i>Print</a>
                        <asp:Button ID="btnCopyToWarranty" runat="server" CssClass="btn btn-warning" 
                            Text="<%$ Resources:GlobalStrings, CopyToWarranty %>" 
                            OnClick="btnCopyToWarranty_Click" />
                    </div>

                </div>
            </div>
        </div>
    </div>
    
    <!-- End common -->
    
    <!-- Details -->
    <div class="row">
        <div class="col-lg-12">
            <div class="panel panel-default">
                <div class="panel-heading">
                    <%=GlobalStrings.Details %>
                </div>
                <div class="panel-body">
                    <ul class="nav nav-tabs">
                        <li class="active"><a href="#tabs-1" data-toggle="tab"><%= GlobalStrings.OutsideService %></a>
                        </li>
                        <li><a href="#tabs-2" data-toggle="tab"><%= GlobalStrings.AtCompany %></a>
                        </li>
                        <%--<li><a href="#tabs-3" data-toggle="tab"><%= GlobalStrings.WarrantyEmployees %></a>
                        </li>--%>
                    </ul>
                    <div class="tab-content">
                        <div class="tab-pane fade in active" id="tabs-1">
                            <div id="ServicesTableContainer"></div>
                            <p></p>
                            <a href="NewService.aspx?ticketId=<%=Request.Params["id"] %>"><%=GlobalStrings.AddNew %></a>
                        </div>
                        <div class="tab-pane fade" id="tabs-2">
                            <div id="ProductsTableContainer"></div>
                            <p></p>
                            <a href="NewProduct.aspx?ticketId=<%=Request.Params["id"] %>"><%=GlobalStrings.AddNew %></a>
                        </div>
                       <%-- <div class="tab-pane fade" id="tabs-3">
                            <div id="EmployeesTableContainer"></div>
                            <p></p>
                            <a href="NewEmployee.aspx?ticketId=<%=Request.Params["id"] %>"><%=GlobalStrings.AddNew %></a>
                        </div>--%>
                    </div>
                </div>
            </div>
        </div>
    </div>
    
    <!-- End details -->
    
    <p>
    </p>
    <div>
        <a class="btn btn-default" href="List.aspx"><%=GlobalStrings.Cancel %></a>
    </div>
    
    <!-- Modal -->
    <div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
        <div class="modal-dialog">
            <div class="modal-content">
                <div class="modal-header">
                    <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
                    <h4 class="modal-title" id="myModalLabel">Xóa</h4>
                </div>
                <div class="modal-body" id="confirmMessage">
                </div>
                <div class="modal-footer">
                    <button type="button" class="btn btn-default" data-dismiss="modal">Cancel</button>
                    <button type="button" class="btn btn-primary" onclick="deleteItem()" data-dismiss="modal">Xóa</button>
                </div>
            </div>
            <!-- /.modal-content -->
        </div>
        <!-- /.modal-dialog -->
    </div>
    <!-- /.modal -->

    <script type="text/javascript">
        $(function () {
            $("#menu-instant").addClass("active");
            $("#menu1-instant").addClass("collapse in");
            $("#instant-ticket").addClass("active");

            $("#<%=txtReceivedDate.ClientID %>").calendar();
            
            LoadProducts();
            LoadServices();
            //LoadEmployees();
        });

        var selectedId = 0, selectedType = 0;
        function deleteClick(delId, delName, delType) {
            selectedId = delId;
            selectedType = delType;
            $('#confirmMessage').html('Bạn có chắc chắn xóa: ' + unescape(delName) + '?');
        }

        function deleteItem() {
            if (selectedId === 0 || selectedType === 0) {
                return;
            }

            switch (selectedType) {
            case 1:
                $.ajax({
                    type: "POST",
                    url: "Edit.aspx/TicketDeleteService",
                    data: JSON.stringify({ Id: selectedId }),
                    contentType: "application/json; charset=utf-8",
                    dataType: "json",
                    success: function() {
                        $('#ServicesTableContainer').jtable('load', { ticketId: <%=Request.Params["id"] %> });
                    },
                    failure: function(errMsg) {
                        alert(errMsg);
                    }
                });
                break;
            case 2:
                $.ajax({
                    type: "POST",
                    url: "Edit.aspx/TicketDeleteProduct",
                    data: JSON.stringify({ Id: selectedId }),
                    contentType: "application/json; charset=utf-8",
                    dataType: "json",
                    success: function() {
                        $('#ProductsTableContainer').jtable('load', { ticketId: <%=Request.Params["id"] %> });
                    },
                    failure: function(errMsg) {
                        alert(errMsg);
                    }
                });
                break;
            case 3:
                break;
            }
        }
    </script>
    
    <script type="text/javascript">
        function LoadProducts() {
            $('#ProductsTableContainer').jtable({
                paging: false,
                pageSize: 10,
                sorting: false,
                //defaultSorting: 'Name ASC',
                actions: {
                    listAction: 'Edit.aspx/TicketProductList'
                    //createAction: 'List.aspx/CreateProduct',
                    //updateAction: 'List.aspx/UpdateProduct',
                    //deleteAction: 'Edit.aspx/TicketDeleteProduct'
                },
                fields: {
                    Id: {
                        key: true,
                        create: false,
                        edit: false,
                        list: false
                    },
                    <%--ProductCode: {
                        title: '<%=GlobalStrings.Code %>'
                    },--%>
                    ProductName: {
                        title: '<%=GlobalStrings.ProductName %>'
                    },
                    Model: {
                        title: '<%=GlobalStrings.Model %>'
                    },
                    <%--ManufacturerName: {
                        title: '<%=GlobalStrings.Manufacturers %>'
                    },--%>
                    Serial: {
                      title: '<%=GlobalStrings.Serial %>'  
                    },
                    <%--WarrantyTypeName: {
                        title: '<%=GlobalStrings.WarrantyType %>'
                    },--%>
                    ErrorName: {
                        title: '<%=GlobalStrings.ErrorCode %>'
                    },
                    <%--WarrantyDate: {
                        title: '<%=GlobalStrings.WarrantyDate %>',
                        type: 'date',
                        displayFormat: 'dd/mm/yy'
                    },--%>
//                    Months: {
//                        title: 'So thang BH'
//                    },
                    //WarrantyCount: {title: 'Lan BH'},
                    <%--SupplierName: {title: '<%=GlobalStrings.Suppliers %>'},--%>
//                    Description: {
//                        title: '<%=GlobalStrings.Description %>',
//                        type: 'textarea'
                    //                    },
                    EmployeeName: {title: '<%=GlobalStrings.TechnicalEmployees %>'},
                    StartDateString: {title: '<%=GlobalStrings.StartDate %>'},
                    EndDateString: {title: '<%=GlobalStrings.EndDate %>'},
                    InstantProductStatusName: {title: '<%=GlobalStrings.Status %>'},
                    Edit: {
                        title: '',
                        width: '1%',
                        sorting: false,
                        display: function (data) {
                            return '<a title="Cập nhật" href="EditProduct.aspx?id=' + data.record.Id + '"><i class="fa fa-2x fa-edit"></i></a>';
                        }
                    },
                    Delete: {
                        title: '',
                        width: '1%',
                        display: function (data) {
                            return '<a title="Xóa" href="#" onclick="deleteClick(' + data.record.Id + ',\'' + escape(data.record.ProductName) + '\', 2)" data-toggle="modal" data-target="#myModal"><i class="fa fa-2x fa-trash-o"></i></a>';
                        }
                    }
                }
            });

            $('#ProductsTableContainer').jtable('load', { ticketId: <%=Request.Params["id"] %> });
        }
        
        function LoadServices() {
            $('#ServicesTableContainer').jtable({
                paging: false,
                pageSize: 10,
                sorting: false,
                actions: {
                    listAction: 'Edit.aspx/TicketServiceList'
                    // deleteAction: 'Edit.aspx/TicketDeleteService'
                },
                fields: {
                    Id: {
                        key: true,
                        create: false,
                        edit: false,
                        list: false
                    },
                    ServiceName: {
                        title: '<%=GlobalStrings.Services %>'
                    },
                    ServiceTypeName: {
                        title: '<%=GlobalStrings.ServiceType %>'
                    },
                    ErrorName: {
                        title: '<%=GlobalStrings.ErrorCode %>'
                    },
                    EmployeeName: {title: '<%=GlobalStrings.TechnicalEmployees %>'},
                    StartDateString: {title: '<%=GlobalStrings.StartDate %>'},
                    EndDateString: {title: '<%=GlobalStrings.EndDate %>'},
                    InstantServiceStatusName: {title: '<%=GlobalStrings.Status %>'},
                    Edit: {
                        title: '',
                        width: '1%',
                        sorting: false,
                        display: function (data) {
                            return '<a title="Cập nhật" href="EditService.aspx?id=' + data.record.Id + '"><i class="fa fa-2x fa-edit"></i></a>';
                        }
                    },
                    Delete: {
                        title: '',
                        width: '1%',
                        display: function (data) {
                            return '<a title="Xóa" href="#" onclick="deleteClick(' + data.record.Id + ',\'' + escape(data.record.ServiceName) + '\', 1)" data-toggle="modal" data-target="#myModal"><i class="fa fa-2x fa-trash-o"></i></a>';
                        }
                    }
                }
            });

            $('#ServicesTableContainer').jtable('load', { ticketId: <%=Request.Params["id"] %> });
        }
        
        function LoadEmployees() {
            $('#EmployeesTableContainer').jtable({
                paging: false,
                pageSize: 10,
                sorting: false,
                actions: {
                    listAction: 'Edit.aspx/TicketEmployeeList',
                    deleteAction: 'Edit.aspx/TicketDeleteEmployee'
                },
                fields: {
                    Id: {
                        key: true,
                        create: false,
                        edit: false,
                        list: false
                    },
                    StartDate: {
                        title: '<%=GlobalStrings.StartDate %>',
                        type: 'date',
                        displayFormat: 'dd/mm/yy'
                    },
                    StartTimeString: {
                        title: 'Giở'
                    },
                    EmployeeName: {
                        title: '<%=GlobalStrings.Name %>'
                    },
                    Description: {
                        title: '<%=GlobalStrings.Description %>'
                    },
                    Edit: {
                        title: '',
                        width: '1%',
                        display: function(data) {
                            return '<input class="jtable-command-button jtable-edit-command-button" onclick="javascript:window.location=\'EditEmployee.aspx?id=' + data.record.Id + '\';" />';
                        }
                    }
                }
            });

            $('#EmployeesTableContainer').jtable('load', { ticketId: <%=Request.Params["id"] %> });
        }
    </script>
</asp:Content>
